{"componentChunkName":"component---src-templates-blog-template-js","path":"/blogs/java-script-2021-new-features","result":{"data":{"blog":{"content":"# JavaScript 2021: New Features\n\n## The latest \n\n- Operators\n- WeakRef\n- Finalizers\n\n> JavaScript is an easy-to-learn programming language which makes it suitable for beginners. Over the years, it has evolved so much that it’s almost everywhere. We’ve seen it on the front-end (React, Angular, or Vue.js), back-end (Node.js), creating a desktop application with ElectronJS, etc.\n\nJavaScript has given some new features in 2021, which helps the developers in many ways. Some of the new features of JavaScript in 2021 are: \n\n#### 1. New Logical Operators:\n\nJavaScript has added three new logical operators to the existing collection. These three operators are, I) &&= , II) ||= , & III) ??= . Before diving into the explanation, take a look at the example code given below:\n\n```\nlet a = 1;\nlet b = 2;\na &&= b;\nconsole.log(a) // output for variable 'a' would be 2.\n```\n\nThe line a&&= b is similar to the code block given below:\n\n```\nif(a) {\n  a = b;\n}\n```\n\nThis logical operator is saying that if the variable **a** has a truthy value (which it is since it holds a non-zero value), then variable **a** should be assigned the value of the variable **b**. That’s why when we do **console.log(a)** , the value of the variable **a** evaluates to **2** instead of **1**.\n\n#### 2) String ‘replaceAll’ method: \n\nWe all have used the string replace method to replace a character or words in a string with the element we specified. But it came with one limitation, this method only replaced the first occurrence of the character or word that we wanted to replace and the rest of the occurrences in the string remained the same. To replace all the characters or words, we have to use regular expressions.\n\nExample:\n\n```\n// without regex\nlet str = 'JS is everywhere. JS is amazing!';\nconsole.log(str.replace('JS', 'JavaScript')); // the output would be 'JavaScript is everywhere. JS is amazing!'\n// with regex\nlet str = 'JS is everywhere. JS is amazing!';\nconsole.log(str.replace(/JS/g, 'JavaScript')); // the output would be 'JavaScript is everywhere. JavaScript is amazing!'.\n```\n\nWith the **replaceAll** method, the need for regular expression is eliminated. Consider the code below:\n\n```\nlet str = 'JS is everywhere. JS is amazing!';\nconsole.log(str.replaceAll('JS', 'JavaScript')); // the output would be 'JavaScript is everywhere. JavaScript is amazing!'.\n```\n\n\n![about.jpg](https://images.pexels.com/photos/5483071/pexels-photo-5483071.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260)\n\n\n##### [Read the full source article here... ](https://javascript.plainenglish.io/javascript-2021-new-features-429bc050f4e8)"}},"pageContext":{"slug":"java-script-2021-new-features"}}}